package com.artron.mediaartron.ui.fragment.center;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;

import com.artron.baselib.base.BaseLoadingFragment;
import com.artron.baselib.base.BaseStaticFragment;
import com.artron.mediaartron.R;
import com.artron.mediaartron.base.BaseFragmentPagerAdapter;
import com.artron.mediaartron.ui.helper.TabLayoutHelper;

import butterknife.BindView;

import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.全部;
import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.台历;
import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.挂历;
import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.旅行记;
import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.框画;
import static com.artron.mediaartron.ui.fragment.center.WorksFinishFragment.ContentType.海报;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-11-13.
 */

public class WorksFinishFragment extends BaseStaticFragment {

    @BindView(R.id.WorksFragment_tab)
    protected TabLayout mTabLayout;
    @BindView(R.id.WorksFragment_pager)
    protected ViewPager mViewPager;
    @BindView(R.id.WorksFragment_line)
    protected View mLine;

    public static WorksFinishFragment newInstance() {
        Bundle args = new Bundle();
        WorksFinishFragment fragment = new WorksFinishFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_works;
    }

    @Override
    protected void initView() {
        final BaseFragmentPagerAdapter adapter =  new BaseFragmentPagerAdapter(getChildFragmentManager()) {

            private final ContentType[] titleArr = {全部, 挂历, 旅行记, 台历, 框画, 海报};

            @Override
            public Fragment getItem(int position) {
                return WorksFinishContentFragment.newInstance(titleArr[position]);
            }

            @Override
            public int getCount() {
                return titleArr.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titleArr[position].name();
            }

        };
        mViewPager.setAdapter(adapter);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mTabLayout.setupWithViewPager(mViewPager);
        mLine.setVisibility(View.GONE);


        mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                Fragment fragment = adapter.getFragment(position);
                if (fragment instanceof BaseLoadingFragment) {
                    ((BaseLoadingFragment) fragment).show();
                }
            }
        });
        TabLayoutHelper.setTabViewMargin(mTabLayout);
    }

    enum ContentType{
        全部(""),挂历("guali"),旅行记("lvxingji"),台历("taili"),框画("kuanghua"),海报("haibao");

        private final String mType;

        ContentType(String type) {
            this.mType = type;
        }

        public String getType() {
            return mType;
        }
    }

}
